package com.ljt.kotlinandmvvm.register

import android.text.TextUtils
import android.view.Gravity
import android.view.View
import com.huburt.library.ImagePicker
import com.huburt.library.bean.ImageItem
import com.ljt.base.activity.BaseActivity
import com.ljt.base.dialog.GenderDialog
import com.ljt.base.utils.GlideUtils
import com.ljt.base.utils.LogUtil
import com.ljt.kotlinandmvvm.R
import com.ljt.kotlinandmvvm.databinding.ActivityRegisterBinding
import kotlinx.android.synthetic.main.draw_module_title.view.*

/**
 * @auther :lujiantao
 * @date :2024/5/4 3:13 PM
 * @desc :注册
 */
class RegisterActivity :BaseActivity<ActivityRegisterBinding,RegisterViewModel>(),
    View.OnClickListener {

    private lateinit var falceUrl: String

    override fun getLayoutResId(): Int {
        return R.layout.activity_register
    }

    override fun createViewModel(): RegisterViewModel {
        return RegisterViewModel()
    }

    override fun initView() {
        binding.ilModuleTitle.tvModuleTitle.text = "注册"
        binding.ilModuleTitle.ivModuleBack.setOnClickListener(this)
        binding.tvModuleSex.setOnClickListener(this)
        binding.ivModuleUploadImg.setOnClickListener(this)
    }

    override fun initData() {

    }

    override fun onClick(v: View?) {
        var id = v?.id
        if (id == R.id.ivModuleBack){
            finish()
        }else if(id == R.id.tvModuleSex){
            showGenderDialog()
        }else if (id == R.id.ivModuleUploadImg){
            ImagePicker.pick(this, object : ImagePicker.OnPickImageResultListener {
                override fun onImageResult(imageItems: ArrayList<ImageItem>) {
                    //imageItems只会size为0，不会为null
                    val imagePath:ImageItem = imageItems[0]
                    LogUtil.e("图片路径-->${imagePath.path}")
                    if (!TextUtils.isEmpty(imagePath.path)){
                        falceUrl = imagePath.path.toString()
                        GlideUtils.intentUrlToImage(binding.ivModuleUploadImg.context,
                        falceUrl,binding.ivModuleUploadImg)
                    }
                }
            })
        }
    }

    /**
     * 显示性别选择弹窗
     */
    private fun showGenderDialog() {
        val genderDialog = GenderDialog(this)
        genderDialog.setGravity(Gravity.BOTTOM)
        genderDialog.show()
        genderDialog.setGenderList()
        genderDialog.setOnDialogSelectListener { listBeans ->
            LogUtil.e("选择性别-->$listBeans")
            binding.tvModuleSex.text = listBeans
            genderDialog.dismiss()
        }
    }
}